﻿using System;
using Newtonsoft.Json;

namespace Ecobee.Net
{
	/// <summary>
	/// Notification type.
	/// </summary>
	[JsonConverter(typeof(CamelCaseStringEnumConverter))]
	public enum NotificationType
	{
		None,
		Alert,
		Hvac,
		FurnaceFilter,
		HumidifierFilter,
		DehumidifierFilter,
		Ventilator,
		Ac,
		AirFilter,
		AirCleaner,
		UvLamp,
		Temp,
		LowTemp,
		HighTemp,
		LowHumidity,
		HighHumidity,
		AuxHeat,
		AuxOutdoor
	}

	/// <summary>
	/// The Alert object represents an alert generated either by a thermostat or user which requires user 
	/// attention. It may be an error, or a reminder for a filter change. Alerts may not be modified 
	/// directly but rather they must be acknowledged using the Acknowledge Function.
	/// </summary>
	public class Alert : ApiObject
	{
		#region Private Fields
		private string _acknowledgeRef = string.Empty;
		private DateTime? _date = null;
		private Time _time = Time.Empty;
		private string _severity = string.Empty;
		private string _text = string.Empty;
		private int _alertNumber = 0;
		private string _alertType = string.Empty;
		private bool _isOperatorAlert = false;
		private string _reminder = string.Empty;
		private bool _showIdt = false;
		private bool _showWeb = false;
		private bool _sendEmail = false;
		private string _acknowledgement = string.Empty;
		private bool _remindMeLater = false;
		private string _thermostatIdentifier = string.Empty;
		private NotificationType _notificationType = NotificationType.None;
		#endregion

		[JsonIgnore]
		public override string UniqueKey
		{
			get
			{
				return this.AcknowledgeRef;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "acknowledgeRef")]
		public string AcknowledgeRef
		{
			get
			{
				return _acknowledgeRef;
			}
			set
			{
				_acknowledgeRef = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "date")]
		public DateTime? Date
		{
			get
			{
				return _date;
			}
			set
			{
				_date = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "time")]
		public Time Time
		{
			get
			{
				return _time;
			}
			set
			{
				_time = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "severity")]
		public string Severity
		{
			get
			{
				return _severity;
			}
			set
			{
				_severity = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "text")]
		public string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "alertNumber")]
		public int AlertNumber
		{
			get
			{
				return _alertNumber;
			}
			set
			{
				_alertNumber = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "alertType")]
		public string AlertType
		{
			get
			{
				return _alertType;
			}
			set
			{
				_alertType = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "isOperatorAlert")]
		public bool IsOperatorAlert
		{
			get
			{
				return _isOperatorAlert;
			}
			set
			{
				_isOperatorAlert = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "reminder")]
		public string Reminder
		{
			get
			{
				return _reminder;
			}
			set
			{
				_reminder = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "showIdt")]
		public bool ShowIdt
		{
			get
			{
				return _showIdt;
			}
			set
			{
				_showIdt = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "showWeb")]
		public bool ShowWeb
		{
			get
			{
				return _showWeb;
			}
			set
			{
				_showWeb = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "sendEmail")]
		public bool SendEmail
		{
			get
			{
				return _sendEmail;
			}
			set
			{
				_sendEmail = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "acknowledgement")]
		public string Acknowledgement
		{
			get
			{
				return _acknowledgement;
			}
			set
			{
				_acknowledgement = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "remindMeLater")]
		public bool RemindMeLater
		{
			get
			{
				return _remindMeLater;
			}
			set
			{
				_remindMeLater = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonProperty(PropertyName = "thermostatIdentifier")]
		public string ThermostatIdentifier
		{
			get
			{
				return _thermostatIdentifier;
			}
			set
			{
				_thermostatIdentifier = value;
			}
		}

		/// <summary>
		/// Notification type.
		/// </summary>
		[JsonProperty(PropertyName = "notificationType")]
		public NotificationType NotificationType
		{
			get
			{
				return _notificationType;
			}
			set
			{
				_notificationType = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[JsonIgnore]
		public DateTime DateTimeStamp
		{
			get
			{
				DateTime returnValue = DateTime.Now;

				if (this.Date.HasValue)
				{
					returnValue = this.Date.Value.Add(this.Time);
				}

				return returnValue;
			}
		}

		protected override string OnDeserializeKeyValue(dynamic dataObject)
		{
			return dataObject.acknowledgeRef;
		}
	}
}
